package com.acane.instagram.service.impl;

import com.acane.instagram.mapper.LikeMapper;
import com.acane.instagram.pojo.Result;
import com.acane.instagram.pojo.dto.LikeDTO;
import com.acane.instagram.service.LikeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class LikeServiceImpl extends ServiceImpl<LikeMapper, LikeDTO> implements LikeService {

    @Autowired
    private LikeMapper likeMapper;

    @Override
    public Result getLikeHistory(String userId) {
        List<LikeDTO> likeDTOList = likeMapper.getLikeHistory(userId);
        return Result.success(likeDTOList);
    }

    @Override
    public boolean judgeIfAlreadyLike(String postId, String likerId) {
        LikeDTO likeDTO = likeMapper.judgeIfAlreadyLike(postId, likerId);
        return likeDTO != null;
    }

    @Override
    public int updateTime(String id) {
        Timestamp timestamp = Timestamp.valueOf(LocalDateTime.now());
        return likeMapper.updateTime(id, timestamp);
    }

    @Override
    public LikeDTO getByPostIdAndLikerId(String postId, String likerId) {
        return likeMapper.getByPostIdAndLikerId(postId, likerId);
    }

    @Override
    public int countByPostId(String postId) {
        return likeMapper.countByPostId(postId);
    }


}
